//
//  CHUploadDataDetailCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/17.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHUploadDataDetailCell.h"
@interface CHUploadDataDetailCell ()
{
    UIView *bgView;
    UILabel *titleLabel;
    UIView *lineView;
    UILabel *scoreLabel;
    UILabel *fsLabel;
    UIView *line;
    UILabel *datasizeLabel;
    UILabel *carnonum;
    UILabel *carvinnum;
    UILabel *nonum;
    UILabel *vinnum;
    
    
}

@end
@implementation CHUploadDataDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype)cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHUploadDataDetailCell";
    CHUploadDataDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell =[[CHUploadDataDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = KRGB(239, 239, 249);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self buildUI];
    }
    return self;
}


-(void)buildUI{
   
    bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenW, 190)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:bgView];
    
    
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, UIScreenW - 15, 44)];
    titleLabel.text = @"杭州高德汽车服务有限公司";
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
    [bgView addSubview:titleLabel];
    
    lineView = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(titleLabel.frame), UIScreenW - 15, 1)];
    lineView.backgroundColor = [UIColor colorWithHexString:@"999999" alpha:0.1f];
    [bgView addSubview:lineView];
    
    scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 44 + (190 - 40 - 44) /2, UIScreenW /3, 30)];
    
    scoreLabel.textAlignment = NSTextAlignmentCenter;
    scoreLabel.text = @"97.72";
    scoreLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    scoreLabel.textColor = KRGB(251, 91, 111);
    [bgView addSubview:scoreLabel];
    
    fsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(scoreLabel.frame), UIScreenW /3, 30)];
    fsLabel.textAlignment = NSTextAlignmentCenter;
    fsLabel.font = [UIFont systemFontOfSize:13];
    fsLabel.text = @"分值";
    fsLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:0.7f];
    [bgView addSubview:fsLabel];
    
    line = [[UIView alloc] initWithFrame:CGRectMake(UIScreenW /3, 74, 1, 190 - 44- 60)];
    line.backgroundColor = [UIColor colorWithHexString:@"999999" alpha:0.1f];
    [bgView addSubview:line];
    
    
    
    CGSize uploadSize = [self sizeWithFont:12 text:@"上传数据量"];
    UILabel *uploadLabel = [[UILabel alloc] initWithFrame:CGRectMake(UIScreenW / 3 +10, 10 +44, uploadSize.width, uploadSize.height)];
    uploadLabel.text = @"上传数据量";
    uploadLabel.font = [UIFont systemFontOfSize:12];
    uploadLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [bgView addSubview:uploadLabel];
    
    datasizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(uploadLabel.frame) + 10, 10 +44, UIScreenW -CGRectGetMaxX(uploadLabel.frame) - 20, 20)];
    datasizeLabel.text = @"36";
    datasizeLabel.textAlignment = NSTextAlignmentRight;
    datasizeLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    datasizeLabel.font = [UIFont systemFontOfSize:12];
    [bgView addSubview:datasizeLabel];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(uploadLabel.frame)+ 5, CGRectGetMaxY(uploadLabel.frame) + 20, 5, 5)];
    view1.backgroundColor = KRGB(156, 187, 244);
    view1.layer.cornerRadius = 2.5;
    view1.layer.masksToBounds = YES;
    [bgView addSubview:view1];
    
    CGSize size1 = [self sizeWithFont:10 text:@"车辆号码缺失数"];
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) +3, CGRectGetMaxY(uploadLabel.frame)+15 , size1.width, size1.height)];
    label1.text = @"车辆号码缺失数";
    label1.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    label1.font = [UIFont systemFontOfSize:10];
    [bgView addSubview:label1];
    
    
    carnonum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label1.frame) +10, label1.y, UIScreenW - CGRectGetMaxX(label1.frame) - 20, size1.height)];
    carnonum.font = [UIFont systemFontOfSize:10];
    carnonum.text = @"0";
    carnonum.textAlignment = NSTextAlignmentRight;
    carnonum.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [bgView addSubview:carnonum];
   
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(uploadLabel.frame)+ 5, CGRectGetMaxY(label1.frame) + 20, 5, 5)];
    view2.backgroundColor =  KRGB(156, 187, 244);
    view2.layer.cornerRadius = 2.5;
    view2.layer.masksToBounds = YES;
    [bgView addSubview:view2];
    
    CGSize size2 = [self sizeWithFont:10 text:@"车辆识别代码缺失数"];
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view2.frame) +3, CGRectGetMaxY(label1.frame)+15 , size2.width, size2.height)];
    label2.text = @"车辆识别代码缺失数";
    label2.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    label2.font = [UIFont systemFontOfSize:10];
    [bgView addSubview:label2];
    
    carvinnum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label2.frame) +10  , label2.y, UIScreenW - CGRectGetMaxX(label2.frame) -20, size1.height)];
    carvinnum.font = [UIFont systemFontOfSize:10];
    carvinnum.text = @"0";
    carvinnum.textAlignment = NSTextAlignmentRight;
    carvinnum.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [bgView addSubview:carvinnum];
    
    
    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(uploadLabel.frame)+ 5, CGRectGetMaxY(label2.frame) + 20, 5, 5)];
    view3.backgroundColor =  KRGB(156, 187, 244);
    view3.layer.cornerRadius = 2.5;
    view3.layer.masksToBounds = YES;
    [bgView addSubview:view3];
    
    CGSize size3 = [self sizeWithFont:10 text:@"车辆号码不规范数"];
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view3.frame) +3, CGRectGetMaxY(label2.frame)+15 , size3.width, size3.height)];
    label3.text = @"车辆号码不规范数";
    label3.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    label3.font = [UIFont systemFontOfSize:10];
    [bgView addSubview:label3];
    
    nonum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label3.frame) +10, label3.y, UIScreenW - CGRectGetMaxX(label3.frame) - 20, size1.height)];
    nonum.font = [UIFont systemFontOfSize:10];
    nonum.text = @"0";
    nonum.textAlignment = NSTextAlignmentRight;
    nonum.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [bgView addSubview:nonum];
    
    UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(uploadLabel.frame)+ 5, CGRectGetMaxY(label3.frame) + 20, 5, 5)];
    view4.backgroundColor =  KRGB(156, 187, 244);
    view4.layer.cornerRadius = 2.5;
    view4.layer.masksToBounds = YES;
    [bgView addSubview:view4];
    
    CGSize size4 = [self sizeWithFont:10 text:@"车辆识别码不规范数"];
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view3.frame) +3, CGRectGetMaxY(label3.frame)+15 , size4.width, size4.height)];
    label4.text = @"车辆识别码不规范数";
    label4.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    label4.font = [UIFont systemFontOfSize:10];
    [bgView addSubview:label4];
    
    vinnum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label4.frame) +10, label4.y, UIScreenW - CGRectGetMaxX(label4.frame) -20, size1.height)];
    vinnum.font = [UIFont systemFontOfSize:10];
    vinnum.text = @"0";
    vinnum.textAlignment = NSTextAlignmentRight;
    vinnum.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [bgView addSubview:vinnum];
    
    UILabel *wzLabel = [[UILabel alloc] initWithFrame:CGRectMake(UIScreenW / 3 +10, label1.y +15 , uploadSize.width, uploadSize.height)];
    wzLabel.text = @"完整性";
    wzLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    wzLabel.font = [UIFont systemFontOfSize:12];
    [bgView addSubview:wzLabel];
    
    
    UILabel *gfLabel = [[UILabel alloc] initWithFrame:CGRectMake(UIScreenW / 3 +10, label3.y +15 , uploadSize.width, uploadSize.height)];
    gfLabel.text = @"规范性";
    gfLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    gfLabel.font = [UIFont systemFontOfSize:12];
    [bgView addSubview:gfLabel];
}

-(void)setModel:(UploadDataModel *)model{
    _model = model;
    titleLabel.text = model.name;
    scoreLabel.text = model.allscore;
    datasizeLabel.text = model.datasize;
    carnonum.text = model.carnonum;
    carvinnum.text = model.carvinnum;
    nonum.text = model.nonum;
    vinnum.text = model.vinnum;

}


//返回字符串所占用的尺寸.
-(CGSize)sizeWithFont:(CGFloat)fontSize text:(NSString *)text
{
   
    
    NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:fontSize]};
    CGSize size=[text sizeWithAttributes:attrs];

    return size;
}

@end
